package cnhy.salary.service;

import cnhy.salary.domain.Department;
import com.easy.query.core.proxy.sql.GroupKeys;
import com.easy.query.core.proxy.sql.Select;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.TreeSelect;
import com.ruoyi.common.exception.ServiceException;
import ling.common.EQueryService;
import lombok.var;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Service
public class DepartmentSvc extends EQueryService<Department>{




    public List<Long> childrenIds(Long parentId) {
        var list = queryHelper.CreateItems("select dept_id from sys_dept where find_in_set(?, ancestors )", parentId).resultPkg().queryMap();
        var ids = list.stream().map(p -> (Long) p.get("dept_id")).collect(Collectors.toList());
        return ids;
    }
    public List<TreeSelect> treeSelectFilter(Long parentId, List<TreeSelect> deptTree) {

        for (var item : deptTree) {
            if (Objects.equals(item.getId(),parentId))
                return item.getChildren();
            var re = treeSelectFilter(parentId,item.getChildren());
            if (re != null)
                return re;
        }
        return null;
    }


}
